<%--
  Created by IntelliJ IDEA.
  User: Administrator
  Date: 2021/9/24/024
  Time: 16:52
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <title>登录</title>
    <script src="lib/js/jquery3.6.0.js"></script>
    <script src="lib/js/bootstrap.js"></script>
    <link rel="stylesheet" href="lib/css/bootstrap.css">
</head>
<body>
<div class="container">
    <div class="col-md-2"></div>
    <div class="col-md-8">

        <div class="form-group">
            <label for="exampleInputEmail1">用户名</label>
            <input name="username" type="email" class="form-control" id="exampleInputEmail1" placeholder="Email">
        </div>
        <button id="sub" type="submit" class="btn btn-default">Submit</button>
    </div>
    <div class="col-md-2"></div>

</div>
<script type="text/javascript">
    $(function () {
        var $username = $("#exampleInputEmail1");
        var isEmail = function (email) {
            return /^\w{2,14}$/.test(email);
        };

        $("#sub").click(function (event) {
            event.preventDefault();
            if (isEmail($username.val())) {
                console.log($username.val())
                $.ajax({
                    url: "./login.do",
                    type: "GET",
                    contentType: "text",
                    data: {
                        username:$username.val(),
                        action:"login"
                    },
                    success : function(data) {
                        if (data==="0"){
                            window.location.href="http://192.168.4.8:8080/d0924_homework/userList.jsp"
                        }
                    }
                })
            }else {
                alert("格式错误")
            }
        })
    })
</script>
</body>
</html>
